﻿using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using System;
using System.Collections.Generic;
using System.Formats.Asn1;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YiMeiJiaLibModel.Business.Dto;
using YiMeiJiaLibModel.Enums;
using YiMeiJiaService.Assembly;
using YiMeiJiaService.IService;


namespace YiMeiJiaApp.Pages.Home
{
    public partial class Index
    {
        #region 服务组件

        [Inject] private IAcccount _account { get; set; }
        [Inject] private IGoods _goods { get; set; }

        [Inject] protected NavigationManager Navigation { get; set; }

        [Inject] protected IJSRuntime JSRuntime { get; set; }
        #endregion



        #region 绑定数据

        public List<WxGoodCategoryDto> _categorys { get; set; }

        public List<GoodListDTO> _recommmendGoods { get; set; }
        #endregion
        /// <summary>
        /// 加载事件
        /// </summary>
        /// <returns></returns>
        protected override async Task OnInitializedAsync()
        {

            try
            {
                // 获取分类
                var msg = string.Empty;
                _categorys = await _goods.GetAllCategories(msg);
                // 获取随机推荐商品
                await GetGoodsRecommendList();
            }
            catch (Exception ex)
            {
                throw;
            }
            await base.OnInitializedAsync();
        }
        public  async Task GetGoodsRecommendList()
        {
            string msg = string.Empty;    
            _recommmendGoods = await _goods.GetGoodsRecommendList(msg);
        }


        public   Task GoDetail(int goodsId)
        {
        //   await Shell.Current.GoToAsync($"/Home/Mall/Detail?goods={goodsId}");
             Navigation.NavigateTo($"/Home/Mall/Detail?goods={goodsId}");
            return Task.CompletedTask;  

        }
    }
}
